package com.magic.user.utils;

import org.apache.commons.codec.digest.DigestUtils;
import org.apache.commons.lang3.StringUtils;

import java.util.UUID;

/**
 * @author lan.jianyuan
 * @create 2021-01-31-11:14
 */
public class CodecUtils {
    public static String generateSalt() {
        return StringUtils.replace(UUID.randomUUID().toString(), "-", "");
    }
    
    public static String md5Hex(String password, String salt) {
        if (StringUtils.isBlank(salt)) {
            salt = password.hashCode() + "";
        }
        return DigestUtils.md5Hex(salt + DigestUtils.md5Hex(password));
    }
    public static String shaHex(String password, String salt) {
        if (StringUtils.isBlank(salt)) {
            salt = password.hashCode() + "";
        }
        return DigestUtils.sha512Hex(salt + DigestUtils.sha512Hex(password));
    }
}
